/*
 * custNameAutoComplete.java
 *
 * Created on December 11, 2006, 6:39 PM
 */

package com.hvelektro.ajax;

import com.hvelektro.lookup.dao.LookupDAO;
import com.hvelektro.common.lookup.vo.CustomerVo;
import java.io.*;
import java.util.ArrayList;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author 9034
 * @version
 */
public class custNameAutoComplete extends HttpServlet {
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest1(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
         String ajaxInput = request.getParameter("custName");
        
        
        try {
            ArrayList customerAjaxList = new LookupDAO().getCustomerAjaxList(ajaxInput);
            
            out.println("<ul>");
            for(int i=0;i<customerAjaxList.size();i++){
                CustomerVo customervo =(CustomerVo)customerAjaxList.get(i);
                out.println("<li id="+i+"> "+customervo.getCUSTOMERID()+" "+customervo.getCUSTOMERNAME()+"</li>");
                out.println("<Input type=hidden name=custID"+i+" value="+customervo.getCUSTOMERID()+">");
            }
            out.println("</ul>");
        }catch(Exception e){
               System.out.println("Inside Exfeption");
               e.printStackTrace();
        
        }
        out.close();
        
        
    }
    
    
     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        /* TODO output your page here
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet DataForCutomer</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet DataForCutomer at " + request.getContextPath () + "</h1>");
        out.println("</body>");
        out.println("</html>");
         */
        
        out.println("<ul>");
        out.println("<li id=1>Cust Id : 1 CustName =First</li>");
        out.println("<Input type=hidden name=custID1 value=NewFirst>");
        out.println("<li id=2>Cust Id : 2CustName =Second</li>");
        out.println("<li id =3>Cust Id : 3CustName =Third</li>");
        out.println("</ul>");
   


  /*<li>test3<span/* class="selectme">selectme3</span></li>
<li><b>BOLD</b><span class="selectme">selectme4<b>boldinselectme</b></span></li>
  
  <li><span class="informal">(GET ME NOT)</span>(GET &lt;ME&gt; INSTEAD)<span class="selectme">(forselectme!)</span></li>
  
  <li><span class="selectme">Here we have <a href="_autocomplete_result.html">a link</a> which should work</span></li>
</ul>*/
        out.close();
    }
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
